#include <iostream>
#include <cassert>
#include <cdna_prot.h>
#include <print_sequence.h>

using namespace std;
using namespace cdna_prot;

//void complement_cdna(std::string& cdna);
//void validate_cdna_sequence(std::string& sequence);
//void validate_prot_sequence(std::string& sequence);
//void cdna_index_to_text(std::string& sequence);
//void cdna_text_to_index(std::string& sequence);
//std::string cdna_to_prot(const std::string& cdna);

string prot =
"MERQSVNYKLDVGPEEDEENANGVKTLMVLLAGEGRNEGESGRGLPGSGASAAEGYRAGE"
"ISAGGPAAPVADLMDNSNQEDLGATGCDQEKEKQPEEPVPDSMGDLENVKRVSGPWSTVN"
"PVRVLVPEFRHGWQQSFNVLQLQELESIFQCNHYISTKEANRLARSMGVSEATVQEWFLK"
"RREKYRSYKRL";
string prot_extra =
"MERQSVNYKLDVGPEEDEENANGVKTLMVLLAGEGRNEGESGRGLPGSGASAAEGYRAGE.:123456B"
"ISAGGPAAPVADLMDNSNQEDLGATGCDQEKEKQPEEPVPDSMGDLENVKRVSGPWSTVN"
"PVRVLVPEFRHGWQQSFNVLQLQELESIFQCNHYISTKEANRLARSMGVSEATVQEWFLK"
"RREKYRSYKRL";

string cdna =
"ATGGAGCGACAAAGCGTCAATTACAAGCTTGATGTGGGACCTGAGGAGGATGAGGAAAAT"
"GCGAATGGTGTAAAGACTCTGATGGTCTTGCTGGCTGGAGAGGGAAGAAATGAGGGAGAG"
"AGTGGACGGGGCCTGCCTGGGTCGGGAGCCTCAGCAGCGGAAGGATACAGAGCAGGAGAA"
"ATAAGTGCAGGTGGGCCTGCTGCGCCAGTAGCCGACCTCATGGATAACAGCAACCAAGAG"
"GACCTTGGTGCCACTGGCTGTGACCAGGAGAAGGAGAAGCAGCCAGAGGAGCCAGTCCCT"
"GATTCCATGGGAGATTTGGAAAATGTAAAGCGTGTGTCCGGGCCGTGGTCCACTGTTAAT"
"CCTGTGAGAGTGTTGGTGCCCGAATTCCGCCACGGTTGGCAACAGAGCTTCAATGTGCTG"
"CAACTACAAGAGCTGGAGAGCATCTTCCAGTGCAATCACTACATCAGCACTAAGGAGGCA"
"AATCGCCTGGCAAGATCCATGGGAGTGAGTGAAGCCACAGTGCAGGAATGGTTTTTGAAG"
"AGGAGAGAGAAATACAGGAGTTATAAGAGGCTG";

string cdna_extra =
"ATGGAGCGACAAAGCGTCAATTACAAGCTTGATGTGGGACCTGAGGAGGATGAGGAAAAT123"
"GCGAATGGTGTAAAGACTCTGATGGTCTTGCTGGCTGGAGAGGGAAGAAATGAGGGAGAG"
"AGTGGACGGGGCCTGCCTGGGTCGGGAGCCTCAGCAGCGGAAGGATACAGAGCAGGAGAA456"
"ATAAGTGCAGGTGGGCCTGCTGCGCCAGTAGCCGACCTCATGGATAACAGCAACCAAGAG"
"GACCTTGGTGCCACTGGCTGTGACCAGGAGAAGGAGAAGCAGCCAGAGGAGCCAGTCCCT546"
"GATTCCATGGGAGATTTGGAAAATGTAAAGCGTGTGTCCGGGCCGTGGTCCACTGTTAATQZ--"
"CCTGTGAGAGTGTTGGTGCCCGAATTCCGCCACGGTTGGCAACAGAGCTTCAATGTGCTG"
"CAACTACAAGAGCTGGAGAGCATCTTCCAGTGCAATCACTACATCAGCACTAAGGAGGCA"
"AATCGCCTGGCAAGATCCATGGGAGTGAGTGAAGCCACAGTGCAGGAATGGTTTTTGAAG"
"AGGAGAGAGAAATACAGGAGTTATAAGAGGCTG";

string prot_3_prime_frame1 =
"QPLITPVFLSPLQKPFLHCGFTHSHGSCQAICLLSADVVIALEDALQLL_LQHIEALLPT"
"VAEFGHQHSHRINSGPRPGHTLYIFQISHGIRDWLLWLLLLLLVTASGTKVLLVAVIHEV"
"GYWRSRPTCTYFSCSVSFRC_GSRPRQAPSTLSLISSLSSQQDHQSLYTIRIFLILLRSH"
"IKLVIDALSLH";

string prot_3_prime_frame2 =
"SLL_LLYFSLLFKNHSCTVASLTPMDLARRFASLVLM__LHWKMLSSSCSCSTLKLCCQP"
"WRNSGTNTLTGLTVDHGPDTRFTFSKSPMESGTGSSGCFSFSWSQPVAPRSSWLLLSMRS"
"ATGAAGPPALISPALYPSAAEAPDPGRPRPLSPSFLPSPASKTIRVFTPFAFSSSSSGPT"
"SSL_LTLCRS";


string prot_3_prime_frame3 =
"ASYNSCISLSSSKTIPALWLHSLPWILPGDLPP_C_CSDCTGRCSPALVVAAH_SSVANR"
"GGIRAPTLSQD_QWTTARTHALHFPNLPWNQGLAPLAASPSPGHSQWHQGPLGCCYP_GR"
"LLAQQAHLHLFLLLCILPLLRLPTQAGPVHSLPHFFPLQPARPSESLHHSHFPHPPQVPH"
"QACN_RFVAP";

int main (int argc, char *argv[])
{
	print_fasta(cerr, "protein", prot, 60);
	print_fasta(cerr, "cdna", cdna, 60);

	// convert cdna_extra to index
	cdna_prot::validate_cdna_to_index(cdna_extra);
	//print_fasta(cerr, "cdna validated", cdna_prot::cdna_index_to_text(cdna_extra), 60);
	assert(cdna == cdna_prot::cdna_index_to_text(cdna_extra));

	cdna_prot::validate_prot(prot_extra);
	//print_fasta(cerr, "protein validated", prot_extra, 60);
	assert(prot == prot_extra);

	// convert cdna_extra index to prot
	string translated_prot = cdna_index_to_prot(cdna_extra);
	//print_fasta(cerr, "protein translated", translated_prot, 60);
	assert(translated_prot == prot);

	// complement and reverse cdna extra
	complement_cdna_index(cdna_extra);
	std::reverse(cdna_extra.begin(), cdna_extra.end());
	print_fasta(cerr, "complemented", cdna_prot::cdna_index_to_text(cdna_extra), 60);


	// 3 frame reverse complement
	string translated_reverse_frame1 = cdna_index_to_prot(cdna_extra.substr(0));
	std::replace(translated_reverse_frame1.begin(), translated_reverse_frame1.end(), 'X', '_');
	print_fasta(cout, "3' to 5 Frame 1'", translated_reverse_frame1, 60);
	assert(prot_3_prime_frame1 == translated_reverse_frame1);

	string translated_reverse_frame2 = cdna_index_to_prot(cdna_extra.substr(1));
	std::replace(translated_reverse_frame2.begin(), translated_reverse_frame2.end(), 'X', '_');
	print_fasta(cout, "3' to 5 Frame 2'", translated_reverse_frame2, 60);
	assert(prot_3_prime_frame2 == translated_reverse_frame2);

	string translated_reverse_frame3 = cdna_index_to_prot(cdna_extra.substr(2));
	std::replace(translated_reverse_frame3.begin(), translated_reverse_frame3.end(), 'X', '_');
	print_fasta(cout, "3' to 5 Frame 3'", translated_reverse_frame3, 60);
	assert(prot_3_prime_frame3 == translated_reverse_frame3);
}


